<!DOCTYPE html>
<html>
<head lang="en">
	<meta charset="UTF-8">
<title>带关闭按钮的滚动广告</title>
<style type="text/css">
#main{ text-align:center;}
#float{
	position:absolute;
	left:30px;
	top:60px; 
	z-index:1;
	}
#close{
	position:absolute;
	top:60px;
	left:134px;
	z-index:2;
	cursor:hand;
}
</style>
</head>
<body>
<div id="close" onClick="adv_close()"><img src="images/close.jpg"></div>
<div id="float"><img src="images/advpic.jpg"></div>
<div id="main"><img src="images/contentpic.jpg"></div> 
<script>
	var top1;//距离顶部的高度
	var left1; //距离左边的高度
	var obj = document.getElementById("float");  //取固定层节点
	function inix(){
		if(obj.currentStyle) {
			top1 = parseInt(obj.currentStyle.top);  //获取加载初始距离顶部的距离
			left1 = parseInt(obj.currentStyle.left); //获取加载初始距离左边的距离
		} else {
			top1 =parseInt(document.defaultView.getComputedStyle(obj,null).top);
			left1 = parseInt(document.defaultView.getComputedStyle(obj,null).left);
		}
	}
	function move(){
		var topa = parseInt(document.documentElement.scrollTop||document.body.scrollTop);
	 	var lefta = parseInt(document.documentElement.scrollLeft||document.body.scrollLeft);
	 	obj.style.top = topa + top1+"px";
	 	obj.style.left = lefta + left1+"px";
	}
	function adv_close(){
		obj.style.display = "none";
		 document.getElementById("close").style.display = "none"; 
	}
	window.onload = inix; 
	window.onscroll = move;
</script>
</body>
</html>
